package com.game.raceroom.player.effect.skill
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import com.util.SwfUtil;
	import com.game.raceroom.Room;
	import com.game.raceroom.player.Player;
	import com.game.raceroom.player.effect.Effect;
	public class BlastEffect extends Effect
	{
		private var actor:Player;
		private var room:Room;
		public function BlastEffect(actor:Player,r:Room)
		{
         trace("blast");
			this.actor=actor;
			room=r;
 
			this.effectType=EFFECT_TYPE_BLAST;
			loadMovie();
		}
		private var loadOk:Boolean=false;
		var frame:int=0;
		var step:int=0;
         public override function update():Boolean{
         	if(!loadOk) return true;
         	 mc.visible=true;
            mc.x=actor.actorDisp.mc.x+actor.actorDisp.mc.width/2-mc.width/2;
            mc.y=actor.actorDisp.mc.y+actor.actorDisp.mc.height/2-mc.height/2;
	         if(frame>=mc.totalFrames){
	              actor.actorDisp.removeChild(mc);
		          valid=false;
	         }
	         mc.gotoAndStop(frame);
	         step++;
	         if(step>1){
	         	step=0;
              	frame++;
             }
        	 return true;
         }
         public override function destroy():Boolean{
         	if(!loadOk) return true;
            actor.actorDisp.removeChild(mc);
            this.valid=false;
            return true;
         }
         protected var myLoader:Loader;
         
		public function loadMovie():void{
			myLoader=new Loader();
		    myLoader.contentLoaderInfo.addEventListener(
  	        Event.COMPLETE,function (e:Event):void{initEftOk(e)});
            myLoader.loadBytes(SwfUtil.getEffectSwfStream(SwfUtil.EFT_NAME_BLAST));
      
		}
		private var mc:MovieClip;
        public function initEftOk(e:Event):void{
            mc = myLoader.content as MovieClip;
            mc.visible=false;
            mc.alpha=0.9;
			actor.actorDisp.addChild(mc);
			loadOk=true;
			room._parents.mainCanvas.sound.playEftSound(0);

        } 
	}
}